package com.jade.common.utils;

import org.springframework.util.StringUtils;

public class CommonResponse {
    private String code;
    private String message;
    private Object data;
    public static String SECCESS_CODE = "0000";
    public static String FAIL_CODE = "9999";
    public static String SECCESS_MESSAGE = "成功";
    public static String FAIL_MESSAGE = "失败";

    public static CommonResponse successResponse(String message, Object data) {
        CommonResponse commonResponse = new CommonResponse();
        commonResponse.setData(data);
        commonResponse.setCode(SECCESS_CODE);
        if (StringUtils.isEmpty(message)) {
            commonResponse.setMessage(SECCESS_MESSAGE);
        } else {
            commonResponse.setMessage(message);
        }
        return commonResponse;
    }

    public static CommonResponse successResponse(Object data) {
        return successResponse("", data);
    }

    public static CommonResponse successResponse() {
        return successResponse("", "");
    }

    public static CommonResponse successResponse(String message) {
        return successResponse(message, "");
    }

    public static CommonResponse failResponse(String message, Object data) {
        CommonResponse commonResponse = new CommonResponse();
        commonResponse.setData(data);
        commonResponse.setCode(FAIL_CODE);
        if (StringUtils.isEmpty(message)) {
            commonResponse.setMessage(FAIL_MESSAGE);
        } else {
            commonResponse.setMessage(message);
        }
        return commonResponse;
    }

    public static CommonResponse failResponse(String message) {
        return failResponse(message, "");
    }

    public static CommonResponse failResponse() {
        return failResponse("", "");
    }

    public static CommonResponse failResponse(Object data) {
        return failResponse("", data);
    }

    public String getCode() {
        return this.code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

}
